/**
 * Project Name:HomeActivity
 * Date:2016-7-4下午4:05:30
 * Copyright (c) 2016, askzhao All Rights Reserved.
 *
 */
package com.kkd.kkdapp.activity;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.inputmethod.InputMethodManager;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.kkd.kkdapp.Environment;
import com.kkd.kkdapp.R;
import com.kkd.kkdapp.base.BaseActivity;
import com.kkd.kkdapp.http.entity.FinanceDto;
import com.kkd.kkdapp.http.entity.FinancialPlanningData;
import com.kkd.kkdapp.http.entity.Tags;
import com.kkd.kkdapp.http.manager.HttpCallBack;
import com.kkd.kkdapp.http.manager.KkdHttpClient;
import com.kkd.kkdapp.http.manager.KkdHttpMagager;
import com.kkd.kkdapp.utils.AppUtil;
import com.kkd.kkdapp.utils.DialogUtils;
import com.kkd.kkdapp.utils.LogUtil;
import com.kkd.kkdapp.utils.PreferenceUtils;
import com.kkd.kkdapp.utils.SystemUtils;
import com.kkd.kkdapp.utils.Tools;
import com.kkd.kkdapp.view.CustomScrollView;
import com.kkd.kkdapp.view.CustomScrollView.OnRefreshListener;
import com.kkd.kkdapp.view.CustomScrollView.OnScrollListener;
import com.kkd.kkdapp.view.KKdWebview;
import com.kkd.kkdapp.view.MyProgressbar;
import com.kkd.kkdapp.view.MyRelativeLayout.OnItemClick;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * ClassName: FinancialPlanParticularsActivity <br/>
 * date: 2016-7-14 上午10:59:30 <br/>
 * K计划详情
 * 
 * @author mty
 * @version
 */
public class FinancialPlanParticularsActivity extends BaseActivity implements
		OnClickListener {

	private static final int DETAILS_REQUEST_SUCCESS = 1;
	private static final int DETAILS_REQUEST_FAIL = 2;
	private RelativeLayout financial_planning_questions_bt; // K计划疑问按钮
	private RelativeLayout return_img; // 返回
	private String bidId; // 标的ID
	private CustomScrollView mScrollView; // 下拉刷新
	private int centralHeight;
	private LinearLayout central;
	private RelativeLayout particulars_title;
	private KKdWebview webview;
	private Timer timer = null;
	private TimerTask mTimerTask = null;
	private double balance; // 账户余额
	private RelativeLayout icon_rl1, icon_rl2, icon_rl3, icon_rl4;
	private String[] imaIdArray;
	private String[] textArray;
	private Dialog viewPagerDialog;
	private Dialog videoDialog;
	private RelativeLayout bid_records; // 投标记录
	private RelativeLayout project_course; // 项目历程
	private Button tender_bt; // 投标
	private RelativeLayout counter_rl; // 计算器
	private TextView title_tv; // 标的标题 TextView
	private String bidTitle; // 标的标题
	private String endDateString; // 结束时间
	private TextView purchase_schedule_tv;
	private String bidProgress;
	private TextView amountMultiple_tv; // 起投金额
	private long amountMultiple; // 最多限制金额&倍数
	private long lowestAmount; // 　最低限制金额&起头金额
	private int bidInterest; // 标的年化收益
	private TextView interest_tv; // 年化收益 TextView
	private int acitityRate; // 利率加息
	private TextView rise_tv1; // 加息
	private TextView term_tv; // 投资期限 TextView
	private String bidPeriodWeb;
	private DecimalFormat df = new DecimalFormat("###,###");
	private TextView purchase_amount; // 可购买金额 TextView
	private long bidFreeAmount; // 　标的剩余金额
	private List<Tags> tags;
	private LinearLayout rel_content;
	private RelativeLayout rel_no_content;
	private ImageView icon_img1, icon_img2, icon_img3, icon_img4;
	private TextView icon_tv1, icon_tv2, icon_tv3, icon_tv4;
	private int bidStatus; // 标的状态
	private boolean webFlag = true;
	private String appbiddetail; // 项目描述，风险措施，还款计划 h5 url
	private String poiId = "";
	private int progress = 0;
	private MyProgressbar progressbar;
	private long bidAmount; // 标的总额
	private double interest; // 进度条进度
	private double iinterest;
	private String bidPeriodType; // 期限单位
	private int max = 100;
	private int bidPeriod; // 理财期限
	private int bidPeriodAdd = 0;
	private long totalLixi;
	private String particularsDesc;
	private String FinanceId;
	private long maxAmount; // 限购金额
	private String bidType = "401"; // 　501 快快享福,401K计划
	private int productType; // 产品类型
	private String interestRateString;
	private String appguide; // K计划规则
	private int applyCnt; // 购买笔数
	private TextView number_tv;
	private TextView number_tv1;
	private TextView number_tv2;
	private Dialog oneDialog; // 第一次进入K计划详情弹窗
	private ImageView img_null;
	private TextView tv_null;
	private boolean firstEntry_null = true;
	private RelativeLayout par_ll;

	private Handler mHandler = new Handler() {

		public void handleMessage(android.os.Message msg) {

			switch (msg.what) {
			case DETAILS_REQUEST_SUCCESS:
				updateUI();
				mScrollView.onRefreshComplete();
				break;
			case DETAILS_REQUEST_FAIL:
				// showToast(particularsDesc);
				mScrollView.onRefreshComplete();
				break;
			}
		};
	};
	private TextView total_target_tv;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.kkd.kkdapp.base.BaseActivity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_financial_plan);
		mTintManager.setStatusBarTintResource(0x00000000);
		initView();
		setListener();
		getMessage();
	}

	/******
	 * 
	 * 初始化控件
	 * 
	 *******/
	public void initView() {
		rel_content = (LinearLayout) findViewById(R.id.rel_content);
		rel_no_content = (RelativeLayout) findViewById(R.id.rel_no_content);
		financial_planning_questions_bt = (RelativeLayout) this
				.findViewById(R.id.financial_planning_questions_bt);
		return_img = (RelativeLayout) this.findViewById(R.id.return_img);
		mScrollView = (CustomScrollView) this.findViewById(R.id.pt_sv);
		mScrollView.setHeaderBackgroundResource(R.color.blue_4845a4);
		mScrollView.setArrowImageView(R.drawable.xlistview_arrow_white);
		mScrollView.setGifDrawable(R.drawable.four_white_dot2);
		central = (LinearLayout) this.findViewById(R.id.central);
		webview = (KKdWebview) this.findViewById(R.id.webview);
		webview.setFocusable(true);
		WebSettings webSettings = webview.getSettings();
		// 设置WebView属性，能够执行Javascript脚本
		webSettings.setJavaScriptEnabled(true);
		webview.getSettings().setDefaultTextEncodingName("utf-8");
		// 设置可以访问文件
		webSettings.setAllowFileAccess(true);
		// 设置支持缩放
		webSettings.setBuiltInZoomControls(true);
		webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
		icon_rl1 = (RelativeLayout) this.findViewById(R.id.icon_rl1);
		icon_rl2 = (RelativeLayout) this.findViewById(R.id.icon_rl2);
		icon_rl3 = (RelativeLayout) this.findViewById(R.id.icon_rl3);
		icon_rl4 = (RelativeLayout) this.findViewById(R.id.icon_rl4);
		bid_records = (RelativeLayout) this.findViewById(R.id.bid_records);
		project_course = (RelativeLayout) this
				.findViewById(R.id.project_course);
		tender_bt = (Button) this.findViewById(R.id.tender_bt);
		counter_rl = (RelativeLayout) this.findViewById(R.id.counter_rl);
		title_tv = (TextView) this.findViewById(R.id.title_tv);
		title_tv.setSelected(true);
		purchase_schedule_tv = (TextView) this
				.findViewById(R.id.purchase_schedule_tv);
		amountMultiple_tv = (TextView) this
				.findViewById(R.id.amountMultiple_tv);
		interest_tv = (TextView) this.findViewById(R.id.interest_tv);
		rise_tv1 = (TextView) this.findViewById(R.id.rise_tv1);
		term_tv = (TextView) this.findViewById(R.id.term_tv);
		purchase_amount = (TextView) this.findViewById(R.id.purchase_amount);
		icon_img1 = (ImageView) this.findViewById(R.id.icon_img1);
		icon_img2 = (ImageView) this.findViewById(R.id.icon_img2);
		icon_img3 = (ImageView) this.findViewById(R.id.icon_img3);
		icon_img4 = (ImageView) this.findViewById(R.id.icon_img4);
		icon_tv1 = (TextView) this.findViewById(R.id.icon_tv1);
		icon_tv2 = (TextView) this.findViewById(R.id.icon_tv2);
		icon_tv3 = (TextView) this.findViewById(R.id.icon_tv3);
		icon_tv4 = (TextView) this.findViewById(R.id.icon_tv4);
		progressbar = (MyProgressbar) this.findViewById(R.id.progressbar);
		progressbar.setMax(max);
		particulars_title = (RelativeLayout) this
				.findViewById(R.id.particulars_title);
		total_target_tv = (TextView) findViewById(R.id.total_target_tv);
		number_tv = (TextView) this.findViewById(R.id.number_tv);
		number_tv1 = (TextView) this.findViewById(R.id.number_tv1);
		number_tv2 = (TextView) this.findViewById(R.id.number_tv2);
		img_null = (ImageView) this.findViewById(R.id.img_null);
		tv_null = (TextView) this.findViewById(R.id.tv_null);
		par_ll = (RelativeLayout) this.findViewById(R.id.par_ll);
		if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
			LayoutParams params = particulars_title.getLayoutParams();
			params.height = SystemUtils.dip2px(this, 50);
			particulars_title.setLayoutParams(params);
		}

	}

	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		super.onWindowFocusChanged(hasFocus);
		centralHeight = central.getHeight();
	}

	/*****
	 * 注册监听事件
	 *****/
	public void setListener() {
		financial_planning_questions_bt.setOnClickListener(this);
		return_img.setOnClickListener(this);
		icon_rl1.setOnClickListener(this);
		icon_rl2.setOnClickListener(this);
		icon_rl3.setOnClickListener(this);
		icon_rl4.setOnClickListener(this);
		bid_records.setOnClickListener(this);
		project_course.setOnClickListener(this);
		tender_bt.setOnClickListener(this);
		counter_rl.setOnClickListener(this);
		mScrollView.setOnRefreshListener(new OnRefreshListener() {
			public void onRefresh() {
				webFlag = true;
				requestInterface();
			}
		});
		mScrollView.setOnScrollListener(new OnScrollListener() {

			@Override
			public void onScroll(int scrollY) {
				if (scrollY >= centralHeight) {
					particulars_title.setBackgroundColor(Color
							.parseColor("#4845a4"));
				} else {
					particulars_title.setBackgroundResource(R.drawable.top_bg);
				}
			}
		});

	}

	/***
	 * 获取上个界面传值
	 ***/
	public void getMessage() {
		Intent intent = this.getIntent();
		bidId = intent.getStringExtra("bidId");
		poiId = intent.getStringExtra("poiId");
	}

	@Override
	protected void onResume() {
		super.onResume();
		requestInterface();
		if (PreferenceUtils.getInstance().getLogin(this) == 0) {
			getAccountInfo();
		}
	}

	/******
	 * K计划详情接口
	 ******/
	public void requestInterface() {
		KkdHttpMagager.getInstance().financialPlanningDetails(bidId,
				FinancialPlanningData.class, new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object responseBody) {
						showContent(true);
						firstEntry_null = false;
						FinancialPlanningData data = (FinancialPlanningData) responseBody;
						FinanceDto financeDto = data.getFinanceDto();
						bidTitle = financeDto.getTitle();
						bidProgress = financeDto.getFinanceProgress();
						lowestAmount = financeDto.getMinAmount();
						amountMultiple = financeDto.getStepAmount();
						bidInterest = financeDto.getPreYearRate();
						acitityRate = financeDto.getActivityRate();
						bidPeriodWeb = financeDto.getFinancePeriodWeb();
						bidFreeAmount = financeDto.getLeftAmount();
						tags = data.getTags();
						bidStatus = financeDto.getFinanceStatus();
						appbiddetail = data.getFinanceDesc();
						appguide = data.getAppguide();
						bidAmount = financeDto.getFinanceAmount();
						interest = (1 - (double) bidFreeAmount / bidAmount);
						bidPeriodType = financeDto.getFinancePeriodType();
						bidPeriod = financeDto.getClosedTerm();
						totalLixi = financeDto.getTotalLixi();
						FinanceId = financeDto.getId();
						maxAmount = financeDto.getMaxAmount();
						productType = financeDto.getProductType();
						endDateString = financeDto.getEndDateString();
						if (acitityRate == 0) {
							interestRateString = bidInterest * 0.01 + "";
						} else {
							interestRateString = bidInterest * 0.01 + "+"
									+ acitityRate * 0.01;
						}
						applyCnt = financeDto.getApplyCnt();
						mHandler.sendEmptyMessage(DETAILS_REQUEST_SUCCESS);
					}

					@Override
					public void onFailure(int statusCode, String desc) {
						if (statusCode == 400) {// 说明K计划没有上线
							showContent(false);
						} else if (statusCode == KkdHttpClient.NO_NET) {
							if (firstEntry_null) {
								rel_content.setVisibility(View.GONE);
								rel_no_content.setVisibility(View.VISIBLE);
								img_null.setImageResource(R.drawable.img_null_net);
								tv_null.setText("网络错误，请稍后重试");
								par_ll.setVisibility(View.GONE);
							} else {
								if (!rel_no_content.isShown())
									showToast("网络错误，请稍后重试");
							}
						} else {
							if (firstEntry_null) {
								rel_content.setVisibility(View.GONE);
								rel_no_content.setVisibility(View.VISIBLE);
								img_null.setImageResource(R.drawable.img_null_net);
								tv_null.setText("服务异常，请稍后重试");
								par_ll.setVisibility(View.GONE);
							} else {
								if (!rel_no_content.isShown())
									showToast("服务异常，请稍后重试");
							}
						}
						mHandler.sendEmptyMessage(DETAILS_REQUEST_FAIL);
						title_tv.setText("K计划");
						firstEntry_null = false;
					}
				});
	}

	/************
	 * 更新UI
	 ************/
	public void updateUI() {
		// 共购买多少人
		if (applyCnt == 0) {
			number_tv1.setVisibility(View.INVISIBLE);
			number_tv2.setVisibility(View.INVISIBLE);
			number_tv.setText("暂无记录");
		} else {
			number_tv.setText("" + applyCnt);
			number_tv1.setVisibility(View.VISIBLE);
			number_tv2.setVisibility(View.VISIBLE);
		}
		// 标题
		title_tv.setText(bidTitle);
		// 购买进度
		purchase_schedule_tv.setText(bidProgress + "%");
		// 项目总额
		total_target_tv.setText(df.format(bidAmount / 100) + "元");
		// 起投金额
		amountMultiple_tv.setText(lowestAmount / 100 + "元");
		// 年化收益
		if (acitityRate == 0) {
			interest_tv.setText(Tools.intOrDouble(Double
					.parseDouble(bidInterest * 0.01 + "")));
			rise_tv1.setText("%");
			rise_tv1.setBackgroundResource(0);
		} else {
			interest_tv.setText(Tools.intOrDouble(Double
					.parseDouble(bidInterest * 0.01 + "")));
			rise_tv1.setText("%+"
					+ Tools.intOrDouble(Double.parseDouble(acitityRate * 0.01
							+ "")) + "%");
			rise_tv1.setBackgroundResource(0);
		}
		// 投资期限
		term_tv.setText(bidPeriodWeb);
		// 　可购买金额
		purchase_amount.setText(df.format(bidFreeAmount / 100));
		if (tags.size() == 1) {
			icon_rl1.setVisibility(View.VISIBLE);
		} else if (tags.size() == 2) {
			icon_rl1.setVisibility(View.VISIBLE);
			icon_rl2.setVisibility(View.VISIBLE);
		} else if (tags.size() == 3) {
			icon_rl1.setVisibility(View.VISIBLE);
			icon_rl2.setVisibility(View.VISIBLE);
			icon_rl3.setVisibility(View.VISIBLE);
		} else if (tags.size() == 4) {
			icon_rl1.setVisibility(View.VISIBLE);
			icon_rl2.setVisibility(View.VISIBLE);
			icon_rl3.setVisibility(View.VISIBLE);
			icon_rl4.setVisibility(View.VISIBLE);
		}
		imaIdArray = new String[tags.size()];
		textArray = new String[tags.size()];
		for (int i = 0; i < tags.size(); i++) {
			imaIdArray[i] = tags.get(i).getImageBig();
			textArray[i] = tags.get(i).getNameBig();
			if (i == 0) {
				ImageLoader.getInstance().displayImage(tags.get(i).getImage(),
						icon_img1, R.drawable.mybank_default);
				icon_tv1.setText(tags.get(i).getName());
			} else if (i == 1) {
				ImageLoader.getInstance().displayImage(tags.get(i).getImage(),
						icon_img2, R.drawable.mybank_default);
				icon_tv2.setText(tags.get(i).getName());
			} else if (i == 2) {
				ImageLoader.getInstance().displayImage(tags.get(i).getImage(),
						icon_img3, R.drawable.mybank_default);
				icon_tv3.setText(tags.get(i).getName());
			} else if (i == 3) {
				ImageLoader.getInstance().displayImage(tags.get(i).getImage(),
						icon_img4, R.drawable.mybank_default);
				icon_tv4.setText(tags.get(i).getName());
			}
		}

		// 标的状态
		if (bidStatus == 40) {
			tender_bt.setEnabled(true);
			tender_bt.setText("立即购买");
		} else if (bidStatus == 50) {
			tender_bt.setEnabled(false);
			tender_bt.setText("已投满");
		} else if (bidStatus == 60) {
			tender_bt.setEnabled(false);
			tender_bt.setText("还款中");
		} else if (bidStatus == 70) {
			tender_bt.setEnabled(false);
			tender_bt.setText("已还款");
		}
		if (webFlag) {
			webFlag = false;
			// h5url
			if (PreferenceUtils.getInstance().getLogin(
					FinancialPlanParticularsActivity.this) == 0) {
				String customerIdAndToken = PreferenceUtils.getInstance()
						.getcustomerId(FinancialPlanParticularsActivity.this);
				String[] cat = customerIdAndToken.split("&");
				webview.loadUrl(appbiddetail + "&poiId=" + poiId
						+ "&customerId=" + cat[1] + "&token=" + cat[0]);
			} else {
				webview.loadUrl(appbiddetail + "&poiId=" + poiId
						+ "&customerId=&token=");
			}
		}
		webview.setWebViewClient(new WebViewClient() {
			public boolean shouldOverrideUrlLoading(WebView view,
					final String url) {
				if (url.startsWith("tel:")) {
					Intent intent = new Intent(Intent.ACTION_VIEW, Uri
							.parse(url));
					startActivity(intent);
				} else if (url.startsWith("http:") || url.startsWith("https:")) {

					if (url.indexOf("video") > 0
							&& !SystemUtils.getNetTypeName().equals("WIFI")) {

						if (videoDialog != null) {
							videoDialog.cancel();
							videoDialog = null;
						}
						videoDialog = DialogUtils.generate2BDialog(
								FinancialPlanParticularsActivity.this,
								"您处于非WIFI环境,即将使用流量查看视频,是否继续?", "确定", "取消",
								new OnClickListener() {

									@Override
									public void onClick(View v) {
										videoDialog.dismiss();
										if (!TextUtils.isEmpty(url)) {
											Intent intent = new Intent(
													FinancialPlanParticularsActivity.this,
													KKDWebActivity.class);
											intent.putExtra("url", url);
											// intent.putExtra("titleName",
											// bidTitle);
											startActivity(intent);
										}
									}
								}, new OnClickListener() {

									@Override
									public void onClick(View v) {
										videoDialog.dismiss();

									}
								});
						videoDialog.show();

					} else {
						if (!TextUtils.isEmpty(url)) {
							Intent intent = new Intent(
									FinancialPlanParticularsActivity.this,
									KKDWebActivity.class);
							intent.putExtra("url", url);
							// intent.putExtra("titleName", bidTitle);
							startActivity(intent);
						}
					}

				}
				return true;
			}

			@Override
			public void onReceivedError(WebView view, int errorCode,
					String description, String failingUrl) {
				super.onReceivedError(view, errorCode, description, failingUrl);
			};

			public void onReceivedSslError(WebView view,
					SslErrorHandler handler, SslError error) {
				handler.proceed();
			}
		});
		webview.setFocusable(false);
		iinterest = (double) (interest * 100);
		if (timer != null) {
			timer.cancel();
			timer = null;
		}

		if (mTimerTask != null) {
			mTimerTask.cancel();
			mTimerTask = null;
		}

		if (timer == null)
			timer = new Timer();
		if (mTimerTask == null) {
			mTimerTask = new TimerTask() {

				@Override
				public void run() {
					progress = progress + 1;
					if (progress <= iinterest) {
						handler.sendEmptyMessage(1);
					} else {
						if (iinterest < 1 && iinterest > 0) {
							progressbar.setProgress(1);
						}
						progress = 0;

						mTimerTask.cancel();
						mTimerTask = null;
						timer.cancel();
						timer = null;
					}

				}
			};
		}
		timer.schedule(mTimerTask, 00, 10);

		if (TextUtils.isEmpty(appguide)) {
			financial_planning_questions_bt.setVisibility(View.GONE);
		} else {
			financial_planning_questions_bt.setVisibility(View.VISIBLE);
		}
	}

	Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			if (progress != 0) {
				if (progress == 99) {
					progressbar.setProgress(100);
				} else {
					progressbar.setProgress(progress);
				}
			} else {
				progressbar.setProgress((int) iinterest);
			}
		};
	};

	@Override
	public void onClick(View v) {
		Intent intent;
		switch (v.getId()) {
		case R.id.financial_planning_questions_bt: // K计划疑问按钮
			SystemUtils.onEvent("Regular_Detail_Process", 1);
			if (!TextUtils.isEmpty(appguide)) {
				intent = new Intent(this, KKDWebActivity.class);
				intent.putExtra("url", appguide);
				startActivity(intent);
			}
			break;
		case R.id.return_img: // 返回
			finish();
			break;
		case R.id.bid_records: // 投标记录
			SystemUtils.onEvent("Regular_Detail_Record", 1);
			intent = new Intent(this, FinancialPlanConditionActivity.class);
			intent.putExtra("bidId", FinanceId);
			startActivity(intent);
			break;
		case R.id.project_course: // 项目历程
			SystemUtils.onEvent("Regular_Detail_Process", 1);
			if (FinanceId != null) {
				intent = new Intent(this, KKDWebActivity.class);
				intent.putExtra("url", Environment.getH5Url()
						+ "financeItemPro.html?financeId=" + FinanceId);
				startActivity(intent);
			}
			break;
		case R.id.tender_bt: // 　投标
			SystemUtils.onEvent("Regular_Detail_Bid", 1);
			tenderButton();
			break;
		case R.id.counter_rl: // 计算器
			SystemUtils.onEvent("Regular_Detail_Calculator", 1);
			if (AppUtil.isConnect(this)) {
				DialogUtils.showCalculateWindow(this, v, bidPeriodType,
						bidFreeAmount, bidAmount, totalLixi, bidPeriod,
						bidPeriodAdd);
				softKeyboard();
			}
			break;
		case R.id.icon_rl1:
			if (imaIdArray != null && imaIdArray.length > 0) {
				showViewPagerDialog(1, imaIdArray, textArray);
			}
			break;
		case R.id.icon_rl2:
			if (imaIdArray != null && imaIdArray.length > 0) {
				showViewPagerDialog(2, imaIdArray, textArray);
			}
			break;
		case R.id.icon_rl3:
			if (imaIdArray != null && imaIdArray.length > 0) {
				showViewPagerDialog(3, imaIdArray, textArray);
			}
			break;
		case R.id.icon_rl4:
			if (imaIdArray != null && imaIdArray.length > 0) {
				showViewPagerDialog(4, imaIdArray, textArray);
			}
			break;
		}

	}

	/*******
	 * 投标button跳转
	 *******/
	public void tenderButton() {
		Intent intent;
		if (bidStatus == 40) {

			if (PreferenceUtils.getInstance().getLogin(this) == 0) { // 登陆验证

				if (PreferenceUtils.getInstance().getAutonym(this) == 1) { // 身份认证

					if (PreferenceUtils.getInstance().getBoundBankCard(this) == 1) { // 判定银行卡是否绑定

						intent = new Intent(this, TenderAffirmActivity.class);
						intent.putExtra("bidId", FinanceId);
						intent.putExtra("toMidFlag", "1");
						intent.putExtra("bidTitle", bidTitle);
						intent.putExtra("bidPeriod", bidPeriod);
						intent.putExtra("amountMultiple", amountMultiple);
						intent.putExtra("lowestAmount", lowestAmount);
						intent.putExtra("bidPeriodType", bidPeriodType);
						intent.putExtra("bidInterest", interestRateString);
						intent.putExtra("bidFreeAmount", bidFreeAmount);
						intent.putExtra("maxAmount", maxAmount);
						intent.putExtra("bidAmount", bidAmount);
						intent.putExtra("totalLixi", totalLixi);
						intent.putExtra("bidType", bidType);
						intent.putExtra("productType", productType);
						intent.putExtra("bidPeriodWeb", bidPeriodWeb);
						intent.putExtra("bidPeriodAdd", bidPeriodAdd);
						intent.putExtra("businessType", "6");

						if ("501".equals(bidType)
								&& PreferenceUtils.getInstance().getKkxfStatus(
										FinancialPlanParticularsActivity.this) == 0) {// 为体验标并且没有快快享福特权
							AppUtil.makeToastForCustomer(
									FinancialPlanParticularsActivity.this,
									PreferenceUtils
											.getInstance()
											.getKkxfExt(
													FinancialPlanParticularsActivity.this));
						} else {
							FinancialPlanParticularsActivity.this
									.startActivity(intent);
						}
					} else {
						if (balance == 0) {
							intent = new Intent(this, ForTenderActivity.class);
							intent.putExtra("enterTypeFlag", 5);
							intent.putExtra("bidId", FinanceId);
							intent.putExtra("bidTitle", bidTitle);
							intent.putExtra("bidPeriod", bidPeriod);
							intent.putExtra("bidInterest", interestRateString);
							intent.putExtra("bidFreeAmount", bidFreeAmount);
							intent.putExtra("bidPeriodType", bidPeriodType);
							intent.putExtra("maxAmount", maxAmount);
							intent.putExtra("bidAmount", bidAmount);
							intent.putExtra("totalLixi", totalLixi);
							intent.putExtra("bidType", bidType);
							intent.putExtra("toMidFlag", "1");
							intent.putExtra("bidPeriodWeb", bidPeriodWeb);
							intent.putExtra("bidPeriodAdd", bidPeriodAdd);
							intent.putExtra("businessType", "6");
							intent.putExtra("productType", productType);
							startActivity(intent);
						} else {
							intent = new Intent(this,
									TenderAffirmActivity.class);
							intent.putExtra("bidType", bidType);
							intent.putExtra("bidId", FinanceId);
							intent.putExtra("bidTitle", bidTitle);
							intent.putExtra("bidPeriod", bidPeriod);
							intent.putExtra("amountMultiple", amountMultiple);
							intent.putExtra("lowestAmount", lowestAmount);
							intent.putExtra("bidPeriodType", bidPeriodType);
							intent.putExtra("bidInterest", interestRateString);
							intent.putExtra("bidFreeAmount", bidFreeAmount);
							intent.putExtra("maxAmount", maxAmount);
							intent.putExtra("bidAmount", bidAmount);
							intent.putExtra("totalLixi", totalLixi);
							intent.putExtra("toMidFlag", "1");
							intent.putExtra("bidPeriodWeb", bidPeriodWeb);
							intent.putExtra("bidPeriodAdd", bidPeriodAdd);
							intent.putExtra("businessType", "6");
							intent.putExtra("productType", productType);
							if ("501".equals(bidType)
									&& PreferenceUtils
											.getInstance()
											.getKkxfStatus(
													FinancialPlanParticularsActivity.this) == 0) {// 为体验标并且没有快快享福特权
								AppUtil.makeToastForCustomer(
										FinancialPlanParticularsActivity.this,
										PreferenceUtils
												.getInstance()
												.getKkxfExt(
														FinancialPlanParticularsActivity.this));
							} else {
								FinancialPlanParticularsActivity.this
										.startActivity(intent);
							}
						}

					}

				} else {
					intent = new Intent(this, ForTenderActivity.class);
					intent.putExtra("enterTypeFlag", 5);
					intent.putExtra("bidId", FinanceId);
					intent.putExtra("bidTitle", bidTitle);
					intent.putExtra("bidPeriod", bidPeriod);
					intent.putExtra("bidInterest", interestRateString);
					intent.putExtra("bidPeriodType", bidPeriodType);
					intent.putExtra("bidFreeAmount", bidFreeAmount);
					intent.putExtra("maxAmount", maxAmount);
					intent.putExtra("bidAmount", bidAmount);
					intent.putExtra("totalLixi", totalLixi);
					intent.putExtra("bidType", bidType);
					LogUtil.e("bidPeriod", "" + bidPeriod);
					LogUtil.e("bidPeriodType", "" + bidPeriodType);
					intent.putExtra("toMidFlag", "1");
					intent.putExtra("bidPeriodWeb", bidPeriodWeb);
					intent.putExtra("bidPeriodAdd", bidPeriodAdd);
					intent.putExtra("businessType", "6");
					intent.putExtra("productType", productType);
					this.startActivity(intent);
				}

			} else {
				intent = new Intent(this, LoginActivity.class);
				this.startActivity(intent);

			}
		}
	}

	/**
	 * 
	 * 查询账户余额
	 */
	public void getAccountInfo() {

		KkdHttpMagager.getInstance().getAccountInfoManager(String.class,
				new HttpCallBack() {

					@Override
					public void onSuccess(int statusCode, Object responseBody) {
						try {
							String responseString = responseBody.toString();
							JSONObject data = new JSONObject(responseString);
							balance = data.getDouble("balance");
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}

					@Override
					public void onFailure(int statusCode, String desc) {
					}
				});
	}

	public void softKeyboard() {
		InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
		// 得到InputMethodManager的实例
		if (imm.isActive()) {
			// 如果开启
			imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,
					InputMethodManager.HIDE_NOT_ALWAYS);
			// 关闭软键盘，开启方法相同，这个方法是切换开启与关闭状态的
		}
	}

	private void showViewPagerDialog(int currentItem,
			final String[] imaIdArray, String[] textArray) {
		if (viewPagerDialog != null) {
			viewPagerDialog.cancel();
			viewPagerDialog = null;
		}
		viewPagerDialog = DialogUtils.showCharacteristicDialog(
				FinancialPlanParticularsActivity.this, currentItem, imaIdArray,
				textArray, new OnItemClick() {

					@Override
					public void getPosition(int position) {
						if (tags != null && tags.size() != 0
								&& "安全保障".equals(tags.get(position).getName())) {
							Intent intent = new Intent(
									FinancialPlanParticularsActivity.this,
									KKDWebActivity.class);
							intent.putExtra("url",
									com.kkd.kkdapp.Environment.getH5Url()
											+ "appinsurance.html"); // 正式
							intent.putExtra("titleName", "安全保障");
							startActivity(intent);
							if (viewPagerDialog != null) {
								viewPagerDialog.cancel();
								viewPagerDialog = null;
							}
						}
					}
				});
		viewPagerDialog.show();
	}

	// 第一次进入K计划详情界面的Dialog
	public void oneFinancialParticularsDialog() {
		if (oneDialog != null) {
			oneDialog.cancel();
			oneDialog = null;
		}
		oneDialog = DialogUtils.oneFinancialParticularsDialog(this,
				R.drawable.onedialog1, R.drawable.onedialog2);
		oneDialog.show();
	}

	@Override
	protected void onStop() {
		super.onStop();
		if (mTimerTask != null) {
			mTimerTask.cancel();
			mTimerTask = null;
		}
		if (timer != null) {
			timer.cancel();
			timer = null;
		}
	}

	private void showContent(boolean isShow) {
		if (isShow) {
			rel_content.setVisibility(View.VISIBLE);
			rel_no_content.setVisibility(View.GONE);
			par_ll.setVisibility(View.VISIBLE);
			if (PreferenceUtils.getInstance().getOneFinancialParticularsDialog(
					this)) {
				oneFinancialParticularsDialog();
				PreferenceUtils.getInstance().setOneFinancialParticularsDialog(
						this, false);
			}
		} else {
			rel_content.setVisibility(View.GONE);
			rel_no_content.setVisibility(View.VISIBLE);
			img_null.setImageResource(R.drawable.icon_no_fin);
			tv_null.setText("新的计划准备中，请稍后再来");
			par_ll.setVisibility(View.GONE);
		}
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		if (mTimerTask != null) {
			mTimerTask.cancel();
			mTimerTask = null;
		}
		if (timer != null) {
			timer.cancel();
			timer = null;
		}

		if (oneDialog != null) {
			oneDialog.cancel();
			oneDialog = null;

		}

	}
}
